package 数据结构与算法.查找算法;

public class InsertValueSearch {
    public static void main(String[] args) {

        int[] arr=new int[100];
        for (int i = 0; i < 100; i++) {
            arr[i]=i+1;
        }
        System.out.println(insertValueSearch(arr,0,arr.length-1,0));
    }

    //插值查找
    public static int insertValueSearch(int[] arr,int left,int right,int findVal){
        System.out.println("查找次数");
        if (left>right||findVal<arr[0]||findVal>arr[arr.length-1]){
            return -1;
        }
        //自适应
        int mid=left+(right-left)*(findVal-arr[left])/(arr[right]-arr[left]);
        if (findVal>arr[mid]){
            return insertValueSearch(arr,mid+1,right,findVal);
        }else if (findVal<arr[mid]){
            return insertValueSearch(arr,left,mid-1,findVal);
        }else{
            return mid;
        }
    }


}
